package com.bittech.util;

import com.alibaba.fastjson.JSON;
import com.bittech.util.db_utils.BasedDao;
import com.google.gson.Gson;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @Author: yuisama
 * @Date: 2019-06-04 17:05
 * @Description:封装公共工具，如加载配置文件
 */
public class CommUtil {

    private CommUtil(){}

    /**
     * 加载配置文件
     * @param fileName
     * @return
     */
    public static Properties loadProperties(String fileName) {
        Properties properties = new Properties();
        InputStream in = BasedDao.class.getClassLoader()
                .getResourceAsStream(fileName);
        try {
            properties.load(in);
        } catch (IOException e) {
            System.err.println("加载配置文件失败，请检查文件路径");
        }
        return properties;
    }

    public static String object2Json(Object obj) {
        return JSON.toJSONString(obj);
    }

    public static Object json2Object(String jsonStr,Class objClass) {
        return JSON.parseObject(jsonStr,objClass);
    }
}
